import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { EGuildStructureType } from "../../../../../Message/Public/EGuildStructureType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { GuildEventName } from "../GuildEventName";
//class StructureTimer
    
    export  class StructureTimer
    {
        constructor(arg1: number)
        {
            
            this._leftTime = arg1;
            if (this._secTimer == null) 
            {
                this._secTimer = new SecTimer(1);
            }
            this._secTimer.repeatCount = this._leftTime;
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onUpdateRemainTimeHandler);
            this._secTimer.addListener(TimerType.COMPLETE, this.onSecTimeCompleteHandler);
            this._secTimer.start();
            return;
        }

        public get type(): EGuildStructureType
        {
            return this._type;
        }

        public set type(arg1: EGuildStructureType)
        {
            this._type = arg1;
            return;
        }

        public get leftTime(): number
        {
            return this._leftTime;
        }

        public set leftTime(arg1: number)
        {
            this._leftTime = arg1;
            this._secTimer.repeatCount = this._leftTime;
            return;
        }

        /* internal  */onUpdateRemainTimeHandler(arg1: SecTimer): void
        {
            var loc1;
            var loc2=((loc1 = this)._leftTime - 1);
            loc1._leftTime = loc2;
            Dispatcher.dispatchEvent(new DataEvent(GuildEventName.StrutureRemainTimeUpdate, this._leftTime));
            return;
        }

        /* internal  */onSecTimeCompleteHandler(arg1: SecTimer): void
        {
            this._secTimer.dispose();
            return;
        }

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_type: EGuildStructureType;

        /* internal */ /* var */_leftTime: number;
    }
